import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebController extends GetxController {
  var webController = WebViewController();

  var webUrl = "";

  var progress = 0.obs;

  var tittle = "".obs;

  @override
  void onInit() {
    super.onInit();
    webUrl = Get.arguments["webUrl"];
    webController.setJavaScriptMode(JavaScriptMode.unrestricted);

    webController
        .setNavigationDelegate(NavigationDelegate(onProgress: (int progress) {
      this.progress.value = progress;
    }, onPageFinished: (String url) async {
      tittle.value = await webController.getTitle() ?? "";
    }));
    webController.loadRequest(Uri.parse(webUrl));
  }
}
